var app = getApp()
var util = require("../../utils/util.js")
var reserveModel = require("../../model/appointmentModel.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    cancelModal: false,
    appointment: {},
    projects: [],
    infos: ['重复预约/误预约', '有更好的选择', '不想预约了', '其他原因']
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.init()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },
  init() {
    var node = app.data.appointment
    var arr = node.timeStr.split(" ")
    this.setData({
      appointment: app.data.appointment,
      date: arr[0],
      time: arr[1]
    })
    var that = this
    util.showLoading("加载中")
    reserveModel.getAppointmentProjectList(node.id, res => {
      wx.hideLoading()
      if (res.status == 1) {
        util.failToast(res.msg)
        return
      }
      that.setData({
        projects: res.data
      })
    })
  },
  //取消按钮
  bindCancel() {
    this.setData({
      cancelModal: true
    })
  },
  bindSubmit(e) {
    var info = e.detail.value.info
    var reqBody={
      id: this.data.appointment.id,
      info:info
    }
    var that=this
    reserveModel.cancelReserve(reqBody,res=>{
        if(res.status==1){
          util.failToast(res.msg)
          return;
        }
        util.successToast(res.msg)
        that.setData({
          cancelModal:false
        })
        setTimeout(()=>{
          wx.navigateBack()
        },1500)
    })
  }

})